import axios from "axios"
import qs from "qs"



// 请求拦截
axios.interceptors.request.use(
  function(config) {
    return config;
  },
  function(error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// http response 服务器响应拦截器，这里拦截401错误，并重新跳入登页重新获取token
axios.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    // console.log(error.response)
    if (error.response) {
      switch (error.response.status) {
        case 404:
          // router.push({ name: "Error404" });
          // error.message = '请求出错(404)'
          break;
        case 500:
          //router.push({ name: "Error404" });
          //  error.message = '服务器错误(500)';
          break;

        default:
          error.message = `连接出错(${error.response.status})!`;
      }
    }
    return Promise.reject(error.response.data);
  }
);

export default axios;
